<template>
  <div :class="className" :style="{height:height,width:width}"></div>
</template>

<script>
  import resize from "@/views/dashboard/mixins/resize";
  import echarts from "echarts";

  export default {
    mixins: [resize],
    props: {
      className: {
        type: String,
        default: 'chart'
      },
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '100%'
      },
      projectId: {
        type: Number,
        required: true
      }
    },
    data() {
      return {
        chart: null,
        data: {
          contractTotal: [
            865,
            1236,
            1842,
            684,
            790,
            499
          ],
          finishTotal: [
            681,
            843,
            1268,
            483,
            548,
            324
          ],
          axis: [
            "100章",
            "200章",
            "300章",
            "400章",
            "600章",
            "800章"
          ]
        }
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart();
      })
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      initChart() {
        this.setOptions();
      },
      setOptions() {
        // 加载数据
        this.chart = echarts.init(this.$el, 'macarons');
        let option = {
          backgroundColor: '',
          // backgroundColor:'rgba(128, 128, 128, 0.1)',
          title: {
            // text: '百章完成金额与合同金额统计',
            // subtext: '单位（万元）',
            // left: 'center'
          },
          // calculable : false,
          // tooltip: {
          //   trigger: 'item'
          // },
          tooltip : {
            trigger: 'axis'
          },
          grid: {
            top: 80,
            backgroundColor: 'rgba(128, 128, 128, 0.1)'
          },
          legend: {
            top: 50,
            data: ['合同', '完成'],
            textStyle:{
              color:"#e9ebee"
            }
          },
          yAxis: {
            type: 'value',
            axisLine: {show: true},
            axisTick: {show: true},
            splitArea: {show: false},
            splitLine: {show: false},
          },
          xAxis: [{
            data: this.data.axis,
          }, {
            type: 'category',
            axisLine: {show: false},
            axisTick: {show: false},
            axisLabel: {show: false},
            splitArea: {show: false},
            splitLine: {show: false},
            data: this.data.axis
          }, {
            type: 'category',
            axisLine: {show: false},
            axisTick: {show: false},
            axisLabel: {show: false},
            splitArea: {show: false},
            splitLine: {show: false},
            data: this.data.axis
          },
          ],
          series: [{
            name: '合同',
            type: 'bar',
            itemStyle: {
              normal: {
                color:"#2481ff"
              }
            },
            data: this.data.contractTotal
          }, {
            name: '完成',
            type: 'bar',
            // xAxisIndex: 2,
            itemStyle: {
              normal: {
                color: '#1afffd',
              }
            },
            data: this.data.finishTotal
          }
          ]
        }
        this.chart.setOption(option);
        // if (response.axis.length == 0) {
        //   this.chart.showLoading({
        //     text: '暂无数据',
        //     showSpinner: false,
        //     textColor: 'rgba(0, 255, 255, 255)',
        //     textStyle: {
        //       rich: {
        //         backgroundColor: {
        //           opacity: 1
        //         }
        //       }
        //     },
        //     maskColor: '#0f1325',
        //     fontSize: '26px',
        //     fontWeight: 'bold',
        //     spinnerRadius:20
        //   })
        // } else {
        //   this.chart.hideLoading();
        // }
      }
    }
  }
</script>
